/************************************************************************
 * @file PluginRequirement.cpp
 * @author Ian Chen
 * @version 1.0
 *
 * @section LICENSE
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 3 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
 * General Public License for more details at
 * http://www.gnu.org/licenses/lgpl.html
 *
 ************************************************************************/
#include <plugin/plugin/PluginRequirement.h>

namespace antu
{
namespace plugin
{

void PluginRequirement::copy(const PluginRequirement &requirement)
{
    this->m_oVersion = requirement.requiredVersion();
    this->m_sCode = requirement.code();
}

PluginRequirement::PluginRequirement(const QString &name, int major, int minor, int patch, int build)
    : m_sCode(name)
{
    this->m_oVersion = PluginVersion(major, minor, patch, build);
}

PluginRequirement::PluginRequirement(const QString &name, const QString &version)
    : m_sCode(name)
{
    this->m_oVersion = PluginVersion::toVersion(version);
}

PluginRequirement::PluginRequirement(const QString &name, const PluginVersion &version)
    : m_sCode(name),
      m_oVersion(version)
{
}

PluginRequirement::PluginRequirement(const PluginRequirement &requirement)
{
    this->copy(requirement);
}

QString PluginRequirement::code() const
{
    return this->m_sCode;
}

PluginVersion PluginRequirement::requiredVersion() const
{
    return this->m_oVersion;
}

PluginRequirement &PluginRequirement::operator =(const PluginRequirement &requirement)
{
    this->copy(requirement);
    return *this;
}

bool PluginRequirement::operator ==(const PluginRequirement &requirement) const
{
    return (this->code() == requirement.code() &&
            this->requiredVersion() == requirement.requiredVersion());
}

}
}
